﻿using System.ComponentModel;
using System.Windows.Media;

namespace RealTimeStocks
{
	class ValueWithBackground : INotifyPropertyChanged
	{
		public ValueWithBackground()
		{
			NumberValue = null;
		}

		public ValueWithBackground(decimal val, Color color)
		{
			NumberValue = val;
			ForeColor = new SolidColorBrush(color);
		}

		public ValueWithBackground(decimal val, bool setForeColour)
		{
			NumberValue = val;
			if (setForeColour)
			{
				if (NumberValue < 0)
					ForeColor = new SolidColorBrush(Colors.Red);
				else if (NumberValue > 0)
					ForeColor = new SolidColorBrush(Colors.Green);
				else
					ForeColor = new SolidColorBrush(Colors.Black);
			}
		}

		private decimal? _numberValue;
		public decimal? NumberValue
		{
			get { return _numberValue; }
			set
			{
				_numberValue = value;
				NotifyPropertyChanged("NumberValue");
			}
		}

		private bool _blink;
		public bool Blink
		{
			get { return _blink; }
			set
			{
				_blink = value;
				NotifyPropertyChanged("Blink");
			}
		}

		private Brush _foreColor;
		public Brush ForeColor
		{
			get { return _foreColor; }
			set
			{
				if (_foreColor != value)
				{
					_foreColor = value;
					NotifyPropertyChanged("ForeColor");
				}
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;

		protected void NotifyPropertyChanged(string propName)
		{
			PropertyChangedEventHandler handler = PropertyChanged;
			if (handler != null)
				handler(this, new PropertyChangedEventArgs(propName));
		}
	}
}
